<?php
/**
 * 二叉树结点
 */

namespace Xxb\XxbPhpAlgo;

class BinaryTreeNode
{
    /**
     * 实际存放的数据
     * @var int
     */
    private $value;

    /**
     * 左孩子结点
     * @var self|null
     */
    private $left;

    /**
     * @return mixed
     */
    public function getValue()
    {
        return $this->value;
    }

    /**
     * @param mixed $value
     */
    public function setValue($value)
    {
        if (!is_int($value)) {
            throw new \InvalidArgumentException('value must be integer');
        }
        $this->value = $value;
    }

    /**
     * @return BinaryTreeNode|null
     */
    public function getLeft()
    {
        return $this->left;
    }

    /**
     * @param BinaryTreeNode|null $left
     */
    public function setLeft($left)
    {
        $this->left = $left;
    }

    /**
     * @return BinaryTreeNode|null
     */
    public function getRight()
    {
        return $this->right;
    }

    /**
     * @param BinaryTreeNode|null $right
     */
    public function setRight($right)
    {
        $this->right = $right;
    }

    /**
     * 右孩子结点
     * @var self|null
     */
    private $right;
}
